"""
环境配置基类
"""

from typing import Dict, Any
from abc import ABC, abstractmethod


class BaseConfig(ABC):
    """环境配置基类"""

    @abstractmethod
    def get_config(self) -> Dict[str, Any]:
        """获取配置"""
        pass

    def validate(self) -> bool:
        """验证配置完整性"""
        required_keys = [
            'hosts.host',
            'hosts.account_host',
            'accounts.admin.auth_key',
            'accounts.admin.password'
        ]

        config = self.get_config()

        for key in required_keys:
            keys = key.split('.')
            value = config
            try:
                for k in keys:
                    value = value[k]
            except (KeyError, TypeError):
                raise ValueError(f"配置缺少必需项: {key}")

        return True


# 配置版本管理
CONFIG_VERSION = "1.0.0"
CONFIG_COMPATIBLE_VERSIONS = ["1.0.0"]


def get_config_version():
    """获取配置版本"""
    return CONFIG_VERSION


def is_config_compatible(version: str) -> bool:
    """检查配置版本兼容性"""
    return version in CONFIG_COMPATIBLE_VERSIONS